/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import core.Doctor;
import core.ErrorLogger;
import core.SqlConnection;
import core.User;
import core.Visit;
import gui.PatientForm;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import util.JCalendar.CellType;

/**
 *
 * @author Marcin
 */
public class PopUpMenu_SwojLekarz_2 extends JPopupMenu{
    JMenuItem itDodaj;
    JMenuItem itUsun;
    User me;
    Doctor d;
    PopUpMenu_SwojLekarz_2(final Doctor d,final JCalendar cal, final User me) {
        itDodaj = new JMenuItem("Zarejestruj sie");

        this.d = d;
        this.me = me;

        if(cal.getCalendar().getSelectedRowCount() != 1 || cal.getCalendar().getSelectedColumnCount() != 1 || cal.calendarMap[cal.getCalendar().getSelectedRow()][cal.getCalendar().getSelectedColumn()] != CellType.AVAILABLE){
            itDodaj.setEnabled(false);
        }
        if(cal.getCalendar().getSelectedRowCount() != 1 || cal.getCalendar().getSelectedColumnCount() != 1 || cal.calendarMap[cal.getCalendar().getSelectedRow()][cal.getCalendar().getSelectedColumn()] == CellType.VISIT){
            itDodaj.setEnabled(false);
        }
        itDodaj.addMouseListener(new MouseAdapter(){
            @Override
            public void mouseReleased(MouseEvent e) {
                cal.addEvent(JCalendar.CellType.VISIT);
                int col[] = cal.getCalendar().getSelectedColumns();
                for(int c : col){
                    if(c!=0) {
                       d.addSwojLekarz_Uzytkownik(cal.getSelectedDateStart(c), cal.getSelectedDateEnd(c), me, d);
                    }
                }
                cal.repaint();
            }
        });

        add(itDodaj);
    }
}
